package com.yulongtian.weekCompetition.month202301.week01;

/**
 * 可
 *
 * @author yulongTian
 * @create 2023-01-01 11:55
 */
public class Test03 {
    public static void main(String[] args) {
        System.out.println(minimumPartition("11111", 1));
    }

    public static int minimumPartition(String s, int k) {
        int kLen = 0;

        int tempK = k;
        while (tempK > 0) {
            tempK /= 10;
            kLen++;
        }

        int sLen = s.length();
        if (sLen <= kLen) {
            if (Integer.valueOf(s) <= k) {
                return 1;
            } else {
                return 2;
            }
        }
        int ans = 0;

        for (int i = 0; i < sLen; ) {
            boolean flag = false;
            int j = kLen;
            while (!flag) {
                if (j > 0 && i + j <= sLen) {
                    if (Integer.valueOf(s.substring(i, i + j)) <= k) {
                        flag = true;
                        i += j;
                        ans++;
                    } else {
                        if (j == 1) {
                            return -1;
                        }
                        j--;
                    }
                } else {
                    j--;
                }
            }

        }


        return ans;
    }
}
